mongoose = require "mongoose"
collectionBuilder = require "./collection-builder"
Config= require "./Config"


dbMap={}

###
#  execute：
      appid：连接数据库名
      keep: 是否保持连接不自动关闭，默认fals
      func: 执行方法
###
db=
  execute: (appid, keep, func) ->
    unless appid
      console.log "无效配置：appid=#{appid}, options=#{options}"
      return
    if typeof keep == "function"
      func= keep
      keep= false
    _config= Config.getConfig().mongoose
    conn= mongoose.createConnection "#{_config.url}:#{_config.port}/#{appid}"
    #FIXME 删除数据库要在open事件内操作，否则删除无效
    func appid,conn
    conn.close() unless keep
module.exports = db
